package com.wj.blog.controller;

import com.wj.blog.pojo.Type;
import com.wj.blog.service.TypeServcie;
import com.wj.blog.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Author:   wj
 * Date:     2020/4/10 21:52
 * Description: 分类接口
 */
@RestController
@RequestMapping("/type")
@Slf4j
public class TypeController {
    @Autowired
    TypeServcie typeServcie;

    /**
     * 添加类型
     * @param type
     * @return
     */
    @PostMapping("/add")
    public Result<Object> add(@RequestBody Type type){
        typeServcie.add(type);
        return new Result<Object>("添加成功");
    }

    /**
     * 根据 Id 删除类型
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result<Object> delete(@PathVariable Integer id){
        typeServcie.delete(id);
        return new Result<Object>("删除成功");
    }

    /**
     * 修改分类
     * @param
     * @return
     */
    @PutMapping("/update")
    public Result<Object> update(@RequestBody Type type){
        typeServcie.update(type);
        return new Result<Object>("修改成功");
    }

    /**
     * 后台查询所有
     * @return
     */
    @GetMapping("/listBack")
    public Result<List<Type>> listBack(){
        log.info("{}",typeServcie.listBack());
        return new Result<>(typeServcie.listBack());
    }
}
